<template>
  <div class="app-container">
    <el-row>
      <el-col :span="6" class="tl-left-tree">
        <!-- 树 -->
        <el-input v-model="queryTreeParam.qry_name" placeholder="请输入会议类型名称" @keyup.enter.native="filterTree" ref="treeSearch">
          <el-button current-node-key="" slot="append" icon="el-icon-search" @click="filterTree"></el-button>
        </el-input>
        <el-scrollbar ref="treeScroll" :style="{ height: treeHeight + 'px' }" resizable-key="treeHeight" :resizable-reduce="20" :resizable-refs="['treeSearch']">
          <el-tree class="tl-tree" ref="tree" :data="treeData" node-key="id" :default-expand-all="false" highlight-current :expand-on-click-node="false" :default-expanded-keys="[0]" @node-click="doTreeQuery" :filter-node-method="filterTreeNode"></el-tree>
        </el-scrollbar>
      </el-col>
      <el-col :span="18">
        <el-row>
          <!-- 查询 -->
          <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
            <template slot="search">
              <el-form-item label="名称">
                <el-input v-model="queryParam.qry_name" placeholder=""></el-input>
              </el-form-item>
            </template>
          </tl-list-search>
        </el-row>
        <el-card>
            <el-row>
              <!-- 工具栏 -->
              <tl-list-toolbar ref="toolbar" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0" :isDisplayExport="false">
                <template slot="left-btn"> </template>
              </tl-list-toolbar>
            </el-row>
            <el-row ref="selector">
              <!-- 列表选择 -->
              <div class="table-alert-div" ref="selector">
                <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
                  <template slot="title">
                    已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a
                    >项&nbsp;&nbsp;
                    <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
                  </template>
                </el-alert>
              </div>
            </el-row>
            <el-row>
              <!-- 表格渲染-->
              <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
                <el-table-column type="selection" width="55px" fixed="left"></el-table-column>
                <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
                <el-table-column prop="name" label="名称" width="150px" sortable="custom" sort-by="name" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="dispgeographytype" label="地理类型" width="100px" sortable="custom" sort-by="geographytype" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="dispgradetype" label="级别类型" width="100px" sortable="custom" sort-by="gradetype" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="username" label="创建人" width="150px" sortable="custom" sort-by="username" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="sortcode" label="排序码" width="100px" sortable="custom" sort-by="sortcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="description" label="备注" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="enabled" label="有效" width="100px" sortable="custom" sort-by="enabled" align="center" header-align="center">
                  <template slot-scope="scope">
                    <el-tag v-if="scope.row.enabled === 1" type="success">是</el-tag>
                    <el-tag v-else type="danger">否</el-tag>
                  </template>
                </el-table-column>
                <el-table-column label="操作" width="110px" v-slot="scope" fixed="right">
                  <el-dropdown trigger="hover">
                    <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
                    <el-dropdown-menu>
                      <el-dropdown-item icon="el-icon-edit" @click.native="openEditDialog('editForm', scope.row.id)">编辑</el-dropdown-item>
                      <el-dropdown-item icon="el-icon-delete" @click.native="doDelete(scope.row.id)">删除</el-dropdown-item>
                      <el-dropdown-item icon="el-icon-plus" @click.native="openAddDialog('editForm', scope.row)" :disabled="scope.row.parentid !== 0">添加下级</el-dropdown-item>
                      <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
                </el-table-column>
              </el-table>
            </el-row>
          <!-- 列表分页 -->
          <el-row class="pagebar" ref="pager">
            <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
          </el-row>
        </el-card>
      </el-col>
      <!-- 编辑画面 -->
      <tl-edit ref="editForm" @refresh="doAllRefresh"></tl-edit>
    </el-row>
  </div>
</template>

<script>
/** mixins */
import { mixin_tree_list } from '@tapui/mixins/mixin_tree_list'
/** 子组件 */
import tlEdit from './edit'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'meetTypeManage',
  mixins: [mixin_tree_list],
  components: { tlEdit },
  data() {
    return {
      description: '会议类型-列表查询',
      urlPrefix: '/meet/typeManage/',
      url: {
        queryTree: '/meet/typeManage/queryTreeList',
        queryCodeList: '/meet/typeManage/dataCodeList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'sortcode',
        sord: 'asc'
      }
    }
  },
  methods: {
    // 打开新增对话框之前，检查树节点是否可以添加下级会议类型
    beforeOpenAddDialog(editForm, rowData) {
      let parentid = parseInt(this.selectTreeNode.pid)
      if (parentid === 0 || parentid === -1) return true
      else {
        this.$tap.alert("会议类型最多支持添加两级节点！")
        return false
      }
    },
    // 打开新增对话框后，设置初始值
    afterOpenAddDialog(editForm, rowData) {
      if (rowData) {
        this.$set(this.$refs[editForm].model, 'dispparentid', rowData.name)
        this.$set(this.$refs[editForm].model, 'parentid', rowData.id)
      } else {
        if (this.selectTreeNode && this.selectTreeNode.id > 0) {
          this.$set(this.$refs[editForm].model, 'dispparentid', this.selectTreeNode.name)
          this.$set(this.$refs[editForm].model, 'parentid', this.selectTreeNode.id)
        }
      }
    }
  }
}
</script>

<style scoped></style>

